/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2023-10-21 10:04:04
 * @LastEditors: TT
 * @LastEditTime: 2023-12-20 08:58:59
 */

import 'package:flutter/material.dart';
import 'package:hzy_normal_tool/hzy_normal_tool.dart';

import '../compontents/common_place_holder_widget.dart';

abstract class BaseStateWidget<T extends StatefulWidget> extends State<T>
    with HzyBodyMixin, WidgetsBindingObserver {
  /// 界面初始化完成
  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      interfaceRenderingCompleted();
    });
    WidgetsBinding.instance.addObserver(this);
    super.initState();
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  /*  
   * 整个widget 包裹属性 
   * createScallBody() 
   *   createSafeArea() /// 是否需要被Safe包裹 (默认false)
   *     createSafeBody() /// 是否需要被暂位图包裹(默认falase)
   *       createBody() /// 最底层的widget 需要使用者必须实现
   *  
   */
  @override
  Widget build(BuildContext context) {
    return createScallBody(
      context: context,
    );
  }

  /// 是否需要安全区域widget包裹
  /// 默认false
  @override
  bool configIsNeedSafeArea() {
    return false;
  }

  /// 是否需要占位图
  /// 默认false
  @override
  bool configIsNeedPlaceHolder() {
    return false;
  }

  /// =============== 网络事件 =============== ///

  /// =============== 触发事件 =============== ///
  ///
  /// 界面渲染完成
  void interfaceRenderingCompleted() {}

  /// 刷新界面
  configSetState(
    void Function() fn,
  ) {
    if (mounted) {
      setState(fn);
    }
  }

  /// 点击缺省页触发事件
  tapPlaceHoldWidgetMethod({
    required CommonPlaceHoldType placeHoldType,
  }) {}
}
